package com.tdkj.service.financial.impl;

import java.sql.Timestamp;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.tdkj.model.base.BaseEntity;
import com.tdkj.model.financial.BeanConsumeRecord;
import com.tdkj.model.user.BeanUser;
import com.tdkj.service.BaseService;
import com.tdkj.service.ServiceException;
import com.tdkj.service.financial.IBeanConsumeRecordService;
import com.tdkj.service.financial.IBeanFimamcialAmountChangeRecordService;

@Component
public class BeanConsumeRecordServiceImpl extends BaseService implements
		IBeanConsumeRecordService {

	private IBeanFimamcialAmountChangeRecordService fimamcialAmountChangeRecordService;
	
	@Resource
	public void setFimamcialAmountChangeRecordService(
			IBeanFimamcialAmountChangeRecordService fimamcialAmountChangeRecordService) {
		this.fimamcialAmountChangeRecordService = fimamcialAmountChangeRecordService;
	}
	
	@Override
	public void create(Long userId, Integer money, String unit, Long refId,
			Class<? extends BaseEntity> refClass, String description) throws ServiceException {
		BeanUser user = this.getBaseDao().findById(userId, BeanUser.class);
		
		BeanConsumeRecord bean = new BeanConsumeRecord();
		bean.setMoney(money);
		bean.setUnit(unit);
		bean.setRefId(refId);
		bean.setRefClass(refClass.getName());
		bean.setDescription(description);
		bean.setUser(user);
		bean.setDateTime(new Timestamp(System.currentTimeMillis()));
		this.getBaseDao().save(bean);
		
		fimamcialAmountChangeRecordService.createOut(userId, money, unit, bean.getId(), BeanConsumeRecord.class, description);
	}

}
